﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GameProgressManager : MonoBehaviour {
	public OneProgress[] proList;
	public int index = 0;

	[SerializeField] string gameProgress;
	public string GameProgress {
		get{ return gameProgress; }
		set {
			gameProgress = value;
			//使用Invoke的目的是防止马上激活/禁用脚本导致的错误
			Invoke("OnGameProgressChanged",0f);
			//SendMessage ("OnGameProgressChanged");
			//OnGameProgressChanged ();
		}
	}
	// Use this for initialization
	void Start () {
		proList = GetComponentsInChildren<OneProgress> ();
		OnGameProgressChanged ();
	}
	
	// Update is called once per frame
	void OnGameProgressChanged () {
		for (int i = 0; i < proList.Length; i++) {
			if (proList [i].thisProgress == gameProgress) {
				//false的目的是考虑到了流程从自己跳变到自己的情况，然而无效
				//proList [i].enabled = false;
				proList [i].enabled = true;
				proList [i].StartTask ();
				//proList[i].Invoke("StartTask",0f);
			} else {
				proList [i].enabled = false;
				proList[i].stopProgress();
			}
		}
	}
}
